﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Antioch.Base.PlayerStates
{
    internal class Land : IState
    {
        public void Enter(StateMachine Machine)
        {
            Machine.DrawComponent.Play("Stand", true);
            Machine.PhysicsComponent.PhysicsBody.GetFixtureList().SetFriction(0.8f);
        }

        public void Leave(StateMachine Machine)
        {
            
        }

        public void Update(StateMachine Machine)
        {
            if (!Machine.PhysicsComponent.IsOnGround)
                Machine.Transition(typeof(Fall));
            else
            {
                float FloorAngle = Jemgine.Math.Vector.AngleBetweenVectors(
                    Jemgine.Math.Vector.Normalize(-Machine.PhysicsComponent.Gravity),
                    Machine.PhysicsComponent.GroundNormal);

                if (System.Math.Abs(FloorAngle) > System.Math.PI / 5.0)
                    Machine.Transition(typeof(SlopeSlide));
                else
                    Machine.Transition(typeof(Stand));
            }
        }
    }
}
